//在实际业务处理的时候，往往需要进行多次数据库访问
//这些访问往往逻辑是相同的
//采用Dao层，逻辑层可以对数据库访问进行封装
//避免进行重复的数据库访问开发操作，降低了维护成本

const jwt = require("jsonwebtoken"); // 导入包
const secretKey = "zhangsan"; // 设置密钥

module.exports = class testDao extends require("../model/testModel") {
  // 查找
  static async findTestDao(req, res) {
    let info = req.body;

    await this.findTestList()
      .then((r) => {
        let token = jwt.sign(info, secretKey, { expiresIn: "1day" });
        res.send({ status: 200, message: "ok", token: token, other: r });
      })
      .catch((error) => {
        res.send({ status: 400, message: "error", other: error });
      });
  }
  // 增加
  static async addTestDao(req, res) {
    await this.addTest(req, res)
      .then((result) => {
        res.send({ status: 200, message: "ok", other: result });
      })
      .catch((error) => {
        res.send({ status: 400, message: "error", other: error });
      });
  }
  static async updateTestDao(req, res) {
    await this.updateTest(req, res)
      .then((result) => {
        res.send({ status: 200, message: "ok", other: result });
      })
      .catch((error) => {
        res.send({ status: 400, message: "error", other: error });
      });
  }
  static async deleteTestDao(req, res) {
    await this.deleteTest(req, res)
      .then((result) => {
        res.send({ status: 200, message: "ok", other: result });
      })
      .catch((error) => {
        res.send({ status: 400, message: "error", other: error });
      });
  }
};
export default testDao;
